package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.ArrayAdapterInclude.ShopArrayAdapter;

public class ShopItemActivity extends AppCompatActivity {
  String[] shopData={"hat","cloth","boots"};
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shopitems_view);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle("商品页面");
    setSupportActionBar(toolbar);
    LinkData();






  }

  @Override public boolean onCreateOptionsMenu(Menu menu) {

    menu.add(0,1,0,"返回上层");

    return true;
  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case 1:
        BackToListView();
        break;

    }
    return true;
  }

  private void LinkData() {
    ShopArrayAdapter shopArrayAdapter = new ShopArrayAdapter(this, shopData);
    ListView listView = (ListView) findViewById(R.id.AdapterView);
    listView.setAdapter(shopArrayAdapter);
  }

  private void BackToListView() {
    Intent intent = new Intent(this, ListViewActivity.class);
    startActivity(intent);
  }

}
